< previous page page_506 next page >

Page 506
Listing 23.1 Continued
    sINIfile = App.Path & "\CALLID.INI"
    nComPort = CInt(sGetINIString(sINIfile, "General", "ComPort", "2"))
    sInit = sGetINIString(sINIfile, "General", "InitString", "AT#CID=1")

    With frmMain
        'SET UP THE COM PORT
        .MSComm1.CommPort = nComPort
        .MSComm1.Settings = "9600,N,8,1"
        .MSComm1.InputLen = 0

        'OPEN THE CONNECTION AND SEND THE INIT STRING
        .MSComm1.PortOpen = True
        .MSComm1.Output = sInit + Chr$(13)

        'WAIT A FEW SECONDS FOR MODEM RESPONSE
        nTemp = 0
        bStop = False
        While nTemp < 32000 And bStop = False
            nTemp = nTemp + 1
            If .MSComm1.InBufferCount >= 2 Then
                sTemp = .MSComm1.Input
                If InStr(sTemp, sInit) = 0 Then bStop = True
            End If
        Wend

        'IF THE MODEM DIDN'T SAY OK THEN END
        If InStr(sTemp, "OK") = 0 Then
            MsgBox "Modem did not respond with OK.", vbOK + vbCritical, "Error"
            End
        End If
        DoEvents

        'CLEAR REMAINING BUFFER INPUT
        sTemp = .MSComm1.Input

        'START THE TIMER
        .tmrMain.Enabled = True

    End With

    'DISPLAY CALLER INFORMATION FROM LAST TIME
    nCount = CInt(sGetINIString(sINIfile, "General", "CallCount", "0"))
    DisplayList nCount
    frmMain.Show

End Sub
The code in Listing 23.1, which executes only at program startup, demonstrates how to send and receive commands with the modem. Commands are sent to the modem using the MS Comm Control's Output property. (Note that the carriage return is added, just as you would type it.) In other words, if you want to dial a number using the ATDT command, you simply assign the command to the Output property. In Listing 23.1, this property is used to send the initialization string from the INI file to the modem.

 
< previous page page_506 next page >